package 线程池.作业;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class 创建固定长度的线程池 {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        //创建一个固定的线程池,规定只能存入两个线程
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("任务一");
                    Thread.sleep(3000);
                    System.out.println("完成一");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        executorService.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("任务二");
                System.out.println("完成二");
            }
        });

        executorService.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("任务三");
                System.out.println("完成");
            }
        });

        executorService.shutdown();
    }
}
